<?php
namespace Core\Application;

use Core\Debugger\AlertLevel;
use Core\Debugger\LogEntry;
use \Core\Debugger\Logger;

/**
 * 
 * @namespace Core\Application
 * @author Raphael DE FREITAS (RaphyTheGeek@gmail.com)
 * @version 1.0
 */
final class Application
{
	protected static $_Instance = null;
	
	protected $_ExecStart = 0; 
	
	protected $_ExecEnd = 0; 
	
	private function __construct() {
		
	}
	
	protected static function getInstance() {
		if(is_null(self::$_Instance))
			self::$_Instance = new Application;
		return self::$_Instance;
	}
	
	public static function run() {
		Logger::log(new LogEntry('Application runinng...'));
		self::getInstance()->execStart();
		
		Configuration::getInstance()->addFromFile(ROOT.'configuration.xml');
		Modules::getInstance()->loadModules();
		
		self::getInstance()->execEnd();
		Logger::log(new LogEntry('Application executed in '.self::getInstance()->getExecTime()));
	}
	
	protected function execStart() {
		$mtime = explode(" ",microtime());
		$this->_ExecStart = $mtime[1] + $mtime[0];
	}
	
	protected function execEnd() {
		$mtime = explode(" ",microtime());
		$this->_ExecEnd = $mtime[1] + $mtime[0];
	}
	
	public function getExecTime() {
		return $this->_ExecEnd - $this->_ExecStart;
	}
}
?>